package com.xyzwps.mvckotlin

import com.xyzwps.mvckotlin.exception.BizException
import com.xyzwps.mvckotlin.exception.badRequest
import com.xyzwps.mvckotlin.exception.invalidReqArgs
import com.xyzwps.mvckotlin.exception.unhandled
import org.apache.commons.lang3.RandomStringUtils

fun assertTrue(exp: Boolean, ex: BizException? = null) {
    if (!exp) throw ex ?: unhandled()
}

fun assertReqParam(exp: Boolean, errorMsg: String) {
    if (!exp) throw invalidReqArgs(errorMsg)
}

fun isEmpty(str: String?) = str == null || str.isEmpty()

fun isNotEmpty(str: String?) = !isEmpty(str)

fun randomString(len: Int = 15) = RandomStringUtils.randomAlphabetic(len)!!

